

import java.io.*;
import java.util.*;
import java.sql.*;
import javax.servlet.*;
import javax.servlet.http.*;


/**
 * This is a simple example of an HTTP Servlet.  It responds to the GET
 * method of the HTTP protocol.
 */
public class GreetingServlet extends HttpServlet {
    public void doGet(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {
        response.setContentType("text/html");
        response.setBufferSize(8192);
       
        PrintWriter out = response.getWriter();
       
        out.println("<html>" + "<head><title>Request - Response Servlets</title></head>");
       
        // then write the data of the response
        out.println("<body  bgcolor=\"#cccccc\">" +
                "<img src=\"duke.waving.gif\" alt=\"Duke waving\">" +
                "<h2>Hello, my name is Andrique. My hobby is Bird breeding. What are your name and hobby?</h2>" +
                "<form method=\"get\">" +
                "<table><tr>"+
                "<td>"+
                "<font face='Trebuchet MS'>"+
                "Name:</td><td> <input type=\"text\" name=\"username\" size=\"25\"></td>" + "<p></p>" +
                "</tr>"+
                "<tr><td>"+
                "Hobby:</td><td>  <input type=\"text\" name=\"hobby\" size=\"25\"></td>" + "<p></p>" +
                "</tr>"+
                "<tr><td>"+
                "Address:</td><td>  <input type=\"text\" name=\"address\" size=\"25\"></td>" + "<p></p>" +
                "</tr>"+
                "<tr><td>"+
                "Contact Number:</td><td>  <input type=\"text\" name=\"contact\" size=\"25\"></td>" + "<p></p>" +
                "</tr>"+
                "<tr><td>"+
                "Email address:</td><td>  <input type=\"text\" name=\"email\" size=\"25\"></td>" + "<p></p>" +
                "</tr>"+
                "</font>"+
        		"</table>"+
                "<input type=\"submit\" value=\"Submit\">" +
                "<input type=\"reset\" value=\"Reset\">" + "</form>");
 
        		
        String username = request.getParameter("username");
       
        if ((username != null) && (username.length() > 0)) {
            RequestDispatcher dispatcher =
                    getServletContext()
                    .getRequestDispatcher("/ResponseServlet");
           
            if (dispatcher != null) {
                dispatcher.include(request, response);
            }
        }
       
        out.println("</body></html>");
        out.close();
    }
   
    public String getServletInfo() {
        return "The Hello servlet says hello.";
    }
}